package com.henme.crm.service.product.impl;

import com.henme.crm.dao.product.ProductCategoryMapper;
import com.henme.crm.entity.admin.User;
import com.henme.crm.entity.product.ProductCategory;
import com.henme.crm.service.product.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ruby
 * Date: 13-5-7
 * Time: 下午3:13
 * To change this template use File | Settings | File Templates.
 */


@Service
public  class ProductCategoryServiceImpl implements ProductCategoryService {
    @Autowired
    ProductCategoryMapper   productCategoryMapper;

    @Override
    public void insertProductCategory(ProductCategory productCategory) {
        productCategoryMapper.insertOne(productCategory);
    }

    @Override
    public void updateProductCategory(ProductCategory productCategory) {
        productCategoryMapper.updateOne(productCategory);
    }

    @Override
    public void deleteProductCategory(long id) {
        productCategoryMapper.deleteOne(id);
    }

    @Override
    public ProductCategory selectProductCategory(long id) {
       return  productCategoryMapper.selectOne(id) ;
    }
    public List<ProductCategory> listSub(Long pid) {
        List<ProductCategory> list=  productCategoryMapper.listSub(pid) ;
        for (ProductCategory productCategory : list) {
                  if(productCategoryMapper.listSubCount(productCategory.getId())>0)  {
                      productCategory.setIsParent(true);
                  }
        }
        return  list;
    }
    //取所有的节点
    public List<ProductCategory> getAllList(){
        return  productCategoryMapper.getAllList();
    }
    public  void updateIndexs(long id,long indexs){
        productCategoryMapper.updateIndexs(id,indexs);
    }

    public  void updateIndexs(String [] ids,String [] indexs){
        for (int i = 0; i < ids.length; i++) {
            productCategoryMapper.updateIndexs(Long.parseLong(ids[i].trim()),Long.parseLong(indexs[i].trim()));
        }
    }
}
